\chapter{Scalars}
\index{scalar|(}
\section{Creating Scalars}

\section{Scalar Operations}

\RLaB\ has a wide range of operators to act upon scalars.  The unary
operators defined on scalars are:

   \begin{description}
        \item[--] Unary negation is the highest priority operator. 
                It is the same as multiplying the expression on the
                right of the operator by $-1$.

        \item[++]  Increments the operand.  Operates on the operand
                to the left of the operator. If
                the imaginary part of the operand is zero, only the
                real part is incremented, otherwise both real and
                imaginary parts are incremented.

        \item[-- --]  Decrements the operand.  Operates on the operand
                to the left of the operator. If
                the imaginary part of the operand is zero, only the
                real part is decremented, otherwise both real and
                imaginary parts are decremented.

   \end{description}

Lets look at the various binary operations, for \verb+A binop B+:

   \begin{description}
     \item[+] Adds the operands.

     \item[--] Subtracts the second operand from the first operand.

     \item[*] Multiplies the operands together. 

     \item[/] Divides the first operand by the second operand.

     \item[$\setminus$] Divides the first operand by the second operand. This
is the same as the right division operator on scalars --- it differs only
on matrices.

     \item[./] Divides the first operand by the second operand. This
is the same as the right division operator on scalars --- it differs only
on matrices.

     \item[$.\setminus$] Divides the first operand by the second operand. This
is the same as the right division operator on scalars --- it differs only
on matrices.

     \item[.*] Multiplies the operands together. This is the same
as the \verb+*+ operator on scalars --- it differs only on matrices.


     \item[${}^\wedge{}$] {\verb+A^B+} raises \verb+A+ to the \verb+B+
              power. 

     \item[${.}^\wedge{}$] {\verb+A.^B+} raises \verb+A+ to the
              \verb+B+ power.  This is the same as the normal power
              operator on scalars --- it differs only on matrices.

   \end{description}

The operators that are denoted by two symbols should not
have any white space (or any other characters) between the
two symbols.



\section{Relational Operations}

\RLaB\ relational, equality and logical operators return $1$ if the
expression is true, and $0$ if the expression is false.

The \RLaB\ relational operators are

\begin{description}
\item[$<$] true if the expression on the left hand side is
      less than the expression on the right hand side.   
\item[$< =$] true if the expression on the left hand side is
      less than or equal to the expression on the right hand side.   
\item[$>$] true if the expression on the left hand side is
      greater than the expression on the right hand side.   
\item[$> =$] true if the expression on the left hand side is
      greater than or equal to the expression on the right hand side.   
\end{description}

        The relational operators all have the same precedence.  If the
expression on either side is complex, then comparison is done on magnitudes.
                
        RLaB equality operators are \verb+==+, which is the test for
equality, and \verb+!=+, which is the test for non-equality.  The
equality operators have the same precedence, and are just below the
relational operators, in terms of precedence. 

        \RLaB\ logical operators are \verb+&&+, which is logical and,
and \verb+||+, which is logical or. Logical AND operation has higher
precedence than logical OR. Both logical operators are lower in
precedence than the equality operators.

        The logical operators evaluate left-to-right, however
evaluation does not stop as soon as the result is known, as in C. Full
evaluation in required because the operands are not restricted to
being simple scalars quantities. Cases where the operands are matrices
requires that full operand evaluation occur.

\section{Scalar Functions}


\subsection{Random numbers}
One of the most flexible features in \RLaB\ is the way it can generate
random numbers.  There are only two functions used in random number
creation --- \verb+rand+, and \verb+srand+.  

\verb+srand+ (See Page~\pageref{fn:srand}), is used to set the seed
value that the numbers are produced from.  Using the same seed value
each time will produce the same sequence of random numbers.  You
should use \verb+srand(``clock'')+ if you want a unique sequence.

\verb+rand+  is the function that
actually  produces the random values.  You can choose many different
distributions, though the uniform and normal distributions are likely
to be of most use.  A complete list of distributions is given on
Page~\pageref{fn:rand}. 


\index{scalar|)}





